// // import TurkishTetris_GameStorage from "../../../../hall/Data/TurkishTetris_GameStorage";

import { _decorator, Component, Node, Label, AudioClip, director } from 'cc';
const { ccclass, property } = _decorator;

import { SSS_Consts } from "../../../../../../Script/Data/SSS_Consts";
import { bdlMgr } from "../../../../../../Script/Manager/BundleManager_S";
import SSS_GameEventManager, { SS_GameEventData } from "../../../../../../Script/Manager/SSS_GameEventManager";
import { TurkishTetris_GameData } from "../../../../hall/Data/TurkishTetris_GameData";
import { TurkishTetris_GameStorage } from "../../../../hall/Data/TurkishTetris_GameStorage";
import { SSS_AudioManager } from 'db://assets/Script/Manager/SSS_AudioManager';
import AdManager from 'db://assets/Script/Manager/AdManager';

@ccclass('TurkishTetrisLosePanel')
export default class TurkishTetris_LosePanel extends Component {
    public static Instance: TurkishTetris_LosePanel;
    @property(Node)
    public Button_menu: Node | null = null;
    @property(Node)
    public Button_replay: Node | null = null;
    @property(Node)
    public Button_revive: Node | null = null;
    @property(Label)
    Label_score: Label | null = null;
    @property(Label)
    Label_high_score: Label | null = null;
    index: number;
    onLoad() {
        TurkishTetris_LosePanel.Instance = this;
    }
    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();

        let audio_root = `audio/fail`;
        bdlMgr.getRes<AudioClip>(SSS_Consts.BundleName.AUDIO, audio_root, AudioClip).then(res => {
            SSS_AudioManager.Instance.playSFX(res, false);
        });
    }
    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }
    Refresh() {
        this.Label_score.string = `${TurkishTetris_GameData.GetScore()}`;
        this.Label_high_score.string = `${TurkishTetris_GameStorage.data.high_score}`;

        // this.Label_score.string = `${TurkishTetris_GameData.GetScore()}`;
        // this.Label_high_score.string = `${DragTetris_GameStorage.data.high_score}`;
    }
    AddListener() {
        this.Button_menu.on(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_replay.on(Node.EventType.TOUCH_END, this.On_Button_replay, this);
        this.Button_revive.on(Node.EventType.TOUCH_END, this.On_Button_revive, this);
    }
    RemoveListener() {
        this.Button_menu.off(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_replay.off(Node.EventType.TOUCH_END, this.On_Button_replay, this);
        this.Button_revive.off(Node.EventType.TOUCH_END, this.On_Button_revive, this);
    }
    On_Button_menu() {
        console.log(`On_Button_menu`);

        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Menu);
        SSS_AudioManager.PlayButtonAudio();
    }
    On_Button_replay() {
        console.log(`On_Button_replay`);

        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Replay);
        SSS_AudioManager.PlayButtonAudio();
    }

    On_Button_revive() {
        console.log(`On_Button_revive------------`);

        AdManager.是否看完广告 = false;
        AdManager.Instance.showRewardVideoAd(AdManager.AdsIds.id_reward_vertical, {},
            () => {
                director.emit(SS_GameEventData.广告结束);
                console.log("复活成功！");


                let audio_root = `audio/life received`;
                bdlMgr.getRes<AudioClip>(SSS_Consts.BundleName.AUDIO, audio_root, AudioClip).then(res => {
                    SSS_AudioManager.Instance.playSFX(res, false);
                });

                this.ShowOff();
                SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Revive);
                SSS_AudioManager.PlayButtonAudio();

            },
            () => {
                director.emit(SS_GameEventData.广告结束);

                console.log("复活失败！");
            },
        );
    }
}